package command;

import DTO.PassengerDTO;

import com.gmail.at.vssabinin.train_transport_system_part1.Protocol;
import com.gmail.at.vssabinin.train_transport_system_part1.ReceivedData;

/**
 * Class represents command interface;
 * It checks that the received login password from administer user are correct
 * and in case that it's true sends OK, if it's not that it sends NO.
 */
public class AdminLogIn implements Command {

	private Protocol protocol = new Protocol();
	
	@Override
	public void execute(ReceivedData recived) {
		Protocol.Message message = this.protocol.decodeMessage(recived.data);
		PassengerDTO passenger = (PassengerDTO)message.getObject();
		if ((passenger.getLogin().equals("admin")) && (passenger.getPassword().equals("admin"))) {
			Protocol.Message answer = this.protocol.new Message("ok", null);
			recived.server.send(recived.socket, this.protocol.createMessage(answer));
		} else {
			Protocol.Message answer = this.protocol.new Message("no", null);
			recived.server.send(recived.socket, this.protocol.createMessage(answer));
		}
	}

}
